package com.plug.common.spring.utils;

import com.plug.common.quartz.QuartzManager;
import com.plug.common.quartz.job.QuartzJob;
import org.quartz.SchedulerException;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

import java.util.List;

/**
 * 任务调度停止后，关掉所有的触发器
 */
public class InstantiationTracingBeanPostProcessor implements ApplicationListener<ContextRefreshedEvent> {

    public void onApplicationEvent(ContextRefreshedEvent event) {
        if(event.getApplicationContext().getParent() == null){//root application context 没有parent，他就是老大.
//            IPlugContrastService plugContrastService = (IPlugContrastService) ApplicationContextHelper.getBean("plugContrastService");
//            List<PlugContrast> list = plugContrastService.findTaskAll();
            try {
//                for(PlugContrast plugContrast : list){
//                    QuartzManager.addJob(plugContrast.getTaskId(), plugContrast.getTaskId(), QuartzJob.class, plugContrast.getTimer());
//                }
                QuartzManager.startAll();
            } catch (SchedulerException e) {
                e.printStackTrace();
            }
        }
    }
}
